﻿<?php 
	$hasPermissionRequest = false; 
	$hasPermissionAccept  = false;
	$hasPermissionRemove  = false;
	$hasPermissionDeny    = false;
	//$hasPermissionMessage = 
	if($this->allow('request-partner','Partner','bizprofile')) $hasPermissionRequest = true;
	if($this->allow('accept-partner','Partner','bizprofile'))  $hasPermissionAccept  = true;
	if($this->allow('remove-partner','Partner','bizprofile'))  $hasPermissionRemove  = true;
	if($this->allow('deny-partner','Partner','bizprofile'))    $hasPermissionDeny  = true;
	$hasPermission        = $hasPermissionRequest || $hasPermissionAccept || $hasPermissionRemove || $hasPermissionDeny;

	$partner_type_you_me   = isset($this->partnerYouMe->partner_type)? $this->partnerYouMe->partner_type:null;	
	$partner_status_you_me = isset($this->partnerYouMe->partner_status)?$this->partnerYouMe->partner_status:null;
	
	$partner_type_me_you   = isset($this->partnerMeYou->partner_type)  ? $this->partnerMeYou->partner_type:null;	
	$partner_status_me_you = isset($this->partnerMeYou->partner_status)? $this->partnerMeYou->partner_status:null;
	/*	
	var_dump($partner_type_you_me); 
	var_dump($partner_status_you_me);
	
	var_dump($partner_type_me_you);
	var_dump($partner_status_me_you);	
	*/
?>
<?php if($this->frontEndActive): ?>
	<?php if($this->user_entity == 0): ?>
	<div class="subcolumns pb10">
		<div class="list-icon">
			<div class="icon">&nbsp; </div>
			<div class="list"> <span class="title"><?php echo $this->translator()->widget('manage_content'); ?></span>
				<ul class="subcolumns ptb5 bullet">
					<li class="c50l">
						<?php
							$arrRoutePermission = array(
								'enterprise_id' => $this->enterprise->id,
								'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true)
							);
						?>
						<a href="<?php echo $this->url($arrRoutePermission, 'bizprofile_user_edit_permission'); ?>">
							<?php echo $this->translator()->widget('edit_permission'); ?>
						</a>
					</li>
					<li class="c50l">
						<?php
							$arrRouteGeneral = array(
								'enterprise_id' => $this->enterprise->id,
								'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true)
							);
						?>
						<a href="<?php echo $this->url($arrRouteGeneral, 'bizprofile_user_edit_general_info'); ?>">
							<?php echo $this->translator()->widget('general_info'); ?>
						</a>
					</li>
					<?php if(count($this->infos) > 0): ?>
					<?php foreach ($this->infos as $info): ?>
						<?php
							$arrRouteInfo = array(
								'enterprise_id' => $this->enterprise->id,
								'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
								'info_id' => $info->info_id
							);
						?>
						<li class="c50l"><a href="<?php echo $this->url($arrRouteInfo, 'bizprofile_user_edit_enterprise_info'); ?>"><?php echo $info->info_title; ?></a></li>
					<?php endforeach; ?>
					<?php endif; ?>
				</ul>
			</div>
		</div>
	</div>
	<?php elseif($this->user_entity >= 2): ?>
	<div class="subcolumns pb10">
		<div class="list-icon">
			<div class="icon2">&nbsp;</div>
			<div class="list"> <span class="title"><?php echo $this->translator()->widget('manage_coporation'); ?></span>
				<ul class="subcolumns ptb5 bullet">
					<?php if($this->user_entity >= 3): ?>
						<li id="panelPermission" class="c50l">
					
						<!-- CO QUYEN GUI KET NOI DOI TAC -->
						<?php if ( $partner_type_you_me==null && $partner_status_you_me==null 
								&& $partner_type_me_you==null && $partner_status_me_you==null && $hasPermissionRequest): ?>
						<form method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_add_partner'); ?>" id="addPartner">
							<?php echo $this->tokenElement; ?>
							<input type="hidden" name="enterprise_id" value="<?php echo $this->enterprise_id; ?>"/>
							<input type="hidden" name="relation_id" value="<?php echo $this->relation_id; ?>"/>
							<input type="hidden" name="redirect_url" value="<?php echo $this->url($this->arrPartnerRoute,$this->purl); ?>"/>
							<div class="confirm">
								<a href="javascript:void(0)" onclick="addPartner(); return false;"><span><?php echo $this->translator()->widget('partner_add_as_partner'); ?></span></a>
							</div>
						</form>
						<?php endif;?>
														
						<!-- CO QUYEN CHAP NHAN -->
						<?php if (   $partner_type_you_me== "buddy" && $partner_status_you_me =="pending" 
								  && $partner_type_me_you== "buddy" && $partner_status_me_you =="no" 
								  && $hasPermissionAccept): ?>
							<!-- CHAP NHAN -->
							<form method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_confirm_partner'); ?>" id="confirmPartner">
								<?php echo $this->tokenElement; ?>
								<input type="hidden" name="enterprise_id" value="<?php echo $this->enterprise_id; ?>"/>
								<input type="hidden" name="relation_id" value="<?php echo $this->relation_id; ?>"/>
								<input type="hidden" name="redirect_url" value="<?php echo $this->url($this->arrPartnerRoute,$this->purl); ?>"/>
								<a href="javascript:void(0);" onclick="cofirmPartner();return false;"> 
									<span><?php echo $this->translator()->widget('partner_confirm_partner'); ?></span>
								</a>
							</form>
						<?php endif;?>
						<!-- TU CHOI KET NOI-->
						<?php if (   $partner_type_you_me== "buddy" && $partner_status_you_me =="pending" 
								  && $partner_type_me_you== "buddy" && $partner_status_me_you =="no" 
								  && $hasPermissionDeny): ?>							
							<form method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_denied_partner'); ?>" id="deniedPartner">
								<?php echo $this->tokenElement; ?>
								<input type="hidden" name="enterprise_id" value="<?php echo $this->enterprise_id; ?>"/>
								<input type="hidden" name="relation_id" value="<?php echo $this->relation_id; ?>"/>
								<input type="hidden" name="redirect_url" value="<?php echo $this->url($this->arrPartnerRoute,$this->purl); ?>"/>
								<a href="javascript:void(0)" onclick="deniedPartner(); return false;">
									<span><?php echo $this->translator()->widget('partner_denied_partner'); ?></span>
								</a>
							</form>
						<?php endif;?>
						
						
						<!-- CO QUYEN REMOVE DOI TAC-->
						<?php if (   $partner_type_you_me== "buddy" && $partner_status_you_me =="yes" 
								  && $partner_type_me_you== "buddy" && $partner_status_me_you =="yes" 
								  && $hasPermissionRemove): ?>
								<form id="removePartner" method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_remove_partner'); ?>" id="removePartner">
									<?php echo $this->tokenElement; ?>
									<input type="hidden" name="enterprise_id" value="<?php echo $this->enterprise_id; ?>"/>
									<input type="hidden" name="relation_id" value="<?php echo $this->relation_id; ?>"/>
									<input type="hidden" name="redirect_url" value="<?php echo $this->url($this->arrPartnerRoute,$this->purl); ?>"/>
									<a href="javascript:void(0)" onclick="removePartner();return false;"><span><?php echo $this->translator()->widget('partner_ispartner'); ?></span></a>
								</form>
						<?php endif;?>
						
						<!-- sau khi mình gửi yêu cầu kết nối hiện status chờ xác nhận -->
						<?php if (	 $partner_type_you_me== "buddy" && $partner_status_you_me =="no" 
								  && $partner_type_me_you== "buddy" && $partner_status_me_you =="pending"):
						?>
							<span><?php echo $this->translator()->widget('partner_waiting_respone'); ?></span>										
						<?php endif;?>
						
						<!-- doanh nghiệp này từ chối lời mời kết nối của mình -->
						<?php if (	 $partner_type_you_me== "ignore" && $partner_status_you_me =="denied" 
								  && $partner_type_me_you== "ignore" && $partner_status_me_you =="pending"):
						?>
							<span style="font-size:9px;color:green;"><?php echo $this->translator()->widget('partner_denied_my_request'); ?></span>							
							<form method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_add_partner'); ?>" id="addPartner">
								<?php echo $this->tokenElement; ?>
								<input type="hidden" name="enterprise_id" value="<?php echo $this->enterprise_id; ?>"/>
								<input type="hidden" name="relation_id" value="<?php echo $this->relation_id; ?>"/>
								<input type="hidden" name="redirect_url" value="<?php echo $this->url($this->arrPartnerRoute,$this->purl); ?>"/>
								<div class="confirm">
									<a href="javascript:void(0)" onclick="addPartner(); return false;"><span><?php echo $this->translator()->widget('partner_add_as_partner'); ?></span></a>
								</div>
							</form>
						<?php endif;?>

						<!-- Doanh nghiệp của mình đã từ chối kết nối với doanh nghiệp này -->	
						<?php if (	 $partner_type_you_me== "ignore" && $partner_status_you_me =="pending" 
								  && $partner_type_me_you== "ignore" && $partner_status_me_you =="denied"):
						?>
							<span style="font-size:9px;color:green;"><?php echo $this->translator()->widget('partner_you_had_denied_enterprise'); ?></span>
							<form method="post" action="<?php echo $this->url(array(), 'bizprofile_partner_add_partner'); ?>" id="addPartner">
								<?php echo $this->tokenElement; ?>
								<input type="hidden" name="enterprise_id" value="<?php echo $this->enterprise_id; ?>"/>
								<input type="hidden" name="relation_id" value="<?php echo $this->relation_id; ?>"/>
								<input type="hidden" name="redirect_url" value="<?php echo $this->url($this->arrPartnerRoute,$this->purl); ?>"/>
								<div class="confirm">
									<a href="javascript:void(0)" onclick="addPartner(); return false;"><span><?php echo $this->translator()->widget('partner_add_as_partner'); ?></span></a>
								</div>
							</form>
						<?php endif;?>
						
					</li>
					<?php endif;?>
					<?php
						$arrParamMessage = array(
							'enterprise_id' => $this->enterprise->id,
							'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
							'reply_id' => $this->enterprise->id
						);
					?>
					<!-- CO QUYEN GUI TIN NHAN -->
					<?php if(isset($this->permissionMessage->messaging_permission) && $this->permissionMessage->messaging_permission  == 1) :?>
					<li class="c50l">
						<a href="<?php echo $this->url($arrParamMessage, 'bizprofile_message_add'); ?>">
							<?php echo $this->translator()->widget('send_message'); ?>
						</a>
					</li>
					<?php endif;?>
				</ul>
			</div>
		</div>
	</div>
	<?php endif; ?>
	<script type="text/javascript" charset="utf-8">
		function removePartner(){
			if (confirm("<?php echo $this->translator()->widget('partner_remove_partner'); ?>"))
			{
				$("#removePartner").submit();
			}
		}
		function addPartner(){
			$("#addPartner").submit();
		}
		function cofirmPartner(){
			$("#confirmPartner").submit();
		}
		function deniedPartner(){
			$("#deniedPartner").submit();
		}
	</script>
<?php endif; ?>